home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / BackInUse-c / BackInUse.c next >
Encoding:
Text File  |  1994-12-04  |  5.5 KB  |  182 lines  |  [TEXT/MMCC]

  1. //•---------------------------------------------------------------------------•//
  2. //• "This Old Hack," modernized to run on Think C™ v.5.0.4, by Kenneth A. Long,
  3. //• on 24 July 1993, without the help of Norm Abrahm.  Free, so don't sell.
  4. //•---------------------------------------------------------------------------•//
  5. //• BackInUse.c        Original comments were left in and I added some.
  6. //•---------------------------------------------------------------------------•//
  7. //• Program INUSE.C for the Megamax C compiler
  8. //•  (C) 1986 William Woody, commercial rights reserved
  9.  
  10. //• If you think this program is cute, please send me computer mail and tell
  11. //• me so!  I personally think it's a cute hack, myself, but what do I know.
  12.  
  13. //• Though I don't believe this program has any commercial value,  (or ANY
  14. //• monitary value whatsoever), I have reserved commercial rights anyways.
  15. //• Silly me...  But if you want to give it to your friends, please leave
  16. //• my name on the darn thing; I need to feel appreciated.
  17. //•---------------------------------------------------------------------------•//
  18.  
  19. #include <stdio.h>
  20. #include <quickdraw.h>        //• What they don't tell you is that you need to
  21.                             //• include this for the SRAND macro to work...
  22.  
  23. //extern int Random ();
  24. extern char *malloc ();
  25.  
  26. #define MAXX 480
  27. #define MAXY 300
  28. #define MAXM 400
  29.  
  30. WindowPtr theWindow;
  31. WindowRecord wRecord;
  32. Rect dragRect, linesRect;
  33. Rect windowBounds = { 40, 2, 380, 508 };
  34.  
  35. struct foo {
  36.     double a,b;            //• This is a point which gets to fly around
  37.     struct foo *next;
  38. };
  39.  
  40. main ()
  41. {
  42.     short number,n,x,done = 0;
  43.     struct foo *top,*Ptr,*Ptr2;
  44.     
  45. //    struct {
  46. //        short top, left, bottom, right;
  47. //    } linesRect;
  48.     
  49.     long ticks;        //• For the delay in the "splash" screen.
  50.     
  51.     double mx,my,nx,ny;
  52.     
  53.     MaxApplZone();
  54.  
  55. #ifdef THINK_C
  56.     InitGraf(&thePort);
  57. #else
  58.     InitGraf(&qd.thePort);
  59. #endif
  60.     InitFonts();
  61.     FlushEvents(everyEvent, 0);
  62.     InitWindows();
  63.     InitMenus();
  64.     TEInit();
  65.     InitDialogs(0L);
  66.     InitCursor();
  67.  
  68.     //• We can't drag because mouseDown quits us.  
  69.     //• But it's here if we want to rig it in later.
  70.     dragRect = qd.screenBits.bounds;    
  71.     
  72.     theWindow = NewWindow (&wRecord, &windowBounds, "\pIn Use", true, 0, 
  73.                      (WindowPtr)-1L, false, 0L);
  74.     SetPort (theWindow);
  75.  
  76.  
  77.     //• We add a Rect to the window that we can draw in and erase.
  78.     SetRect (&linesRect,0,0,506,380);
  79. //        40, 2, 380, 508
  80.     //• Make sure there's a clean slate to draw in.
  81.     EraseRect (&linesRect);
  82.         
  83.     MoveTo (10,25);
  84.     TextFont (systemFont);    //• System Font is zero, folks.
  85.     TextSize (12);
  86.     DrawString ("\pProgram InUse.C for the Megamax C compiler");
  87.     MoveTo (10,40);
  88.     DrawString ("\pCopyright©1985 by William Woody, commercial rights reserved.");
  89.     MoveTo (10,55);
  90.     DrawString ("\pTo halt the program, press the mouse Button.");
  91.     TextFont (courier);        //• Change font to Courier 12 bold.
  92.     TextSize (12);    
  93.     TextFace (bold);
  94.     MoveTo (10,70);
  95.     DrawString ("\pMade to run on Code Warrior on 7 November 1994");
  96.     MoveTo (10,85);
  97.     DrawString ("\pBy Kenneth A. Long");    
  98.     GetDateTime ((unsigned long*) &qd.randSeed);    //• Seed the random number generator
  99.     TextFont (0);
  100.     TextSize (12);    //• Set all the font stuff back so our SysParams are OK.
  101.     TextFace (0);
  102.     Delay (240L, &ticks);
  103.     EraseRect (&linesRect);        //• Get ready for action, after bragging.
  104.     
  105.     while  (!done) 
  106.     {
  107.         EraseRect (&linesRect);        //• Added to not stack drawings up.
  108.         number =  (Random () & 3) + 2;    //• Number of points generated.
  109.         x = 0;
  110.             
  111.         top = Ptr = (struct foo *) malloc(sizeof(struct foo));
  112.  
  113.         //• While horizontal incrementing value is not the same 
  114.         //• as number of points...
  115.         while  (x++ != number)
  116.     
  117.         //• ...this stuff is what it is (?).
  118.         Ptr =  (Ptr->next = (struct foo *) malloc (sizeof(struct foo)));
  119.         Ptr =  (Ptr->next = top);
  120.         
  121.         mx = 0;
  122.         my = 0;
  123.         nx = 9999999.0;        //• Large numbers for finding minimum value.
  124.         ny = 9999999.0;
  125.         do 
  126.         {
  127.             Ptr->a =  (double) Random ();
  128.             if  (Ptr->a > mx) mx = Ptr->a;
  129.             if  (Ptr->a < nx) nx = Ptr->a;
  130.             Ptr->b =  (double) Random ();
  131.             if  (Ptr->b > my) my = Ptr->b;
  132.             if  (Ptr->b < ny) ny = Ptr->b;
  133.             Ptr = Ptr->next;
  134.             
  135.         } 
  136.         //• As long as Ptr ain't the same as top...
  137.         while  (Ptr != top);
  138.             do         //• ...make up the points and create "a".
  139.             {        //• A circularly linked list of points.
  140.                 Ptr->a =  (Ptr->a - nx) * MAXX /  (mx - nx);
  141.                 Ptr->b =  (Ptr->b - ny) * MAXY /  (my - ny);
  142.                 Ptr = Ptr->next;    //• Ptr points to next point.
  143.             } 
  144.         //• Again, as long as Ptr ain't the same as top...
  145.         while  (Ptr != top);
  146.             n = 0;        //• ..."n" has 0 value.
  147.             MoveTo ( (int) Ptr->a, (int) Ptr->b);
  148.             
  149.             //• While that's true, and while incrementing "n" is not the 
  150.             //• same as 400 times the number of points generated...
  151.             while  (n++ != MAXM * number)    
  152.             {    //• ...move the points around, like this:
  153.                 
  154.                 //• Give "Ptr->a" a value of ITSELF times 40, PLUS
  155.                 //• the value of "Ptr->next->a" (see above "do loop"),
  156.                 //• then divide that product by 41.  That's the H coord.
  157.                 Ptr->a =  (Ptr->a * 40 + Ptr->next->a) / 41;
  158.                 
  159.                 //• Same for be to get the V coord.
  160.                 Ptr->b =  (Ptr->b * 40 + Ptr->next->b) / 41;
  161.                 
  162.                 //• Then draw the line.
  163.                 LineTo ( (int)Ptr->a, (int)Ptr->b);
  164.                 
  165.                 Ptr = Ptr->next;
  166.                 if  (Button ())    //• Halt program when Button is pressed.
  167.                 {
  168.                     done = 1;    //• It's one DONE puppy!
  169.                     break;        //• Unconditionally get the hell out.
  170.                 }
  171.             }    //• done with "while".
  172.             
  173.             Ptr = top;    //• Clean up the circular linked list.
  174.             do 
  175.             {
  176.                 Ptr =  (Ptr2 = Ptr)->next;
  177.                 free (Ptr2);
  178.             } 
  179.             while  (Ptr != top);    //• As long as Ptr aint the top.
  180.         EraseRect (&linesRect);
  181.     }
  182. }